package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: admin
 * @Description:
 * @Date: 2019/5/28 11:37
 */

public class JdkProxy implements InvocationHandler {

    private Object target;

    public JdkProxy(){
    }
    public JdkProxy(Object target){
        this.target=target;
    }

    public Object bind(Object target) {
        this.target=target;
        return Proxy.newProxyInstance(this.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("--------1-------");
//        method.invoke(proxy,args);
        Object res=method.invoke(target,args);
        System.out.println("--------2-------");
        return res;
    }
}
